package us.mooresr.webtroopmanager.client.ui;

import us.mooresr.webtroopmanager.client.place.AdminPlace;
import us.mooresr.webtroopmanager.client.place.EventListPlace;
import us.mooresr.webtroopmanager.client.place.PeopleListPlace;
import us.mooresr.webtroopmanager.client.place.VehicleListPlace;
import us.mooresr.webtroopmanager.shared.Privilege;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

public class DashboardViewImpl extends Composite implements DashboardView {
	
	private Presenter presenter ;
	
	private static DashboardViewUiBinder uiBinder = GWT.create(DashboardViewUiBinder.class);
	
	interface DashboardViewUiBinder extends UiBinder<Widget, DashboardViewImpl> {
		
	}
	
	@UiField
	Button peopleButton;
	
	@UiField
	Button vehiclesButton;
	
	@UiField
	Button eventsButton;
	
	@UiField
	Button logoutButton;
	
	@UiField 
	Button adminButton;
	
	@UiField
	Label statusLabel;
	
	@UiHandler("peopleButton")
	void onClickPeopleButton(ClickEvent e) {
		presenter.goTo(new PeopleListPlace());
	}
	
	@UiHandler("eventsButton")
	void onClickEventsButton(ClickEvent e) {
		presenter.goTo(new EventListPlace());
	}
	
	@UiHandler("vehiclesButton")
	void onClickVehiclesButton(ClickEvent e) {
		presenter.goTo(new VehicleListPlace());
	}
	
	@UiHandler("logoutButton")
	void onClickLogoutButton(ClickEvent e) {
		presenter.doLogout();
	}
	
	@UiHandler("adminButton")
	void onClickAdminButton(ClickEvent e) {
		presenter.goTo(new AdminPlace());
	}


	
	public DashboardViewImpl() {
		initWidget(uiBinder.createAndBindUi(this));
	}
	
	@Override
	public void setPresenter(Presenter presenter) {
		this.presenter = presenter;
		
	}

	@Override
	public void permissionsChanged() {
		if (presenter.hasPermission(Privilege.ADMIN)){		
			adminButton.setVisible(true);
		} else {
			adminButton.setVisible(false);
		}
	}

	@Override
	public void setStatus(String status) {
		statusLabel.setText(status);
		
	}


}
